import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false

// 自用css
import '../public/css/common.css'
import '../public/css/main.css'

import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
// @ts-ignore
Vue.use(ViewUI);

// ElementUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI);

// 工具类
// @ts-ignore
import MenuRouter from './utils/MenuRouter';
// @ts-ignore
import FormValidate from './utils/FormValidate';
// @ts-ignore
import Config from './utils/Config';
// @ts-ignore
import NetUtil from './utils/NetUtil';
// @ts-ignore
import InfoUtil from './utils/InfoUtil';
// @ts-ignore
import Validater from './utils/Validater';
// @ts-ignore
import DoubleUtil from './utils/DoubleUtil';
import StoreUtil from './utils/StoreUtil';

Vue.prototype.InfoUtil = InfoUtil;
Vue.prototype.NetUtil = NetUtil;
Vue.prototype.MenuRouter = MenuRouter;
Vue.prototype.FormValidate = FormValidate;
Vue.prototype.Config = Config;
Vue.prototype.Validater = Validater;
Vue.prototype.DoubleUtil = DoubleUtil;
Vue.prototype.StoreUtil = StoreUtil;
Vue.use(MenuRouter);
Vue.use(FormValidate);
Vue.use(Config);
Vue.use(NetUtil);
Vue.use(InfoUtil);
Vue.use(Validater);
Vue.use(DoubleUtil);
Vue.use(StoreUtil);

// Vue-Resourcew
import Vueresource from 'vue-resource';

Vue.use(Vueresource);
// @ts-ignore
Vue.http.interceptors.push((request, next) => {
  // 设置token
  request.headers.set('token', store.state.token);
  // @ts-ignore
  next((response) => {
    var result = response.body;
    if (result == null || result.errorCode === 106 || result.errorCode === 107) {
      // 登录过期
      Vue.prototype.$Modal.error({
        title: '登录过期',
        content: '登录过期,请重新登录后查看',
        onOk: function () {
          // 返回登录页面
          router.push('/login');
        }
      });
    }
    return response;

  });

});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
